package com.itheim.chinamobileai.tool;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheim.chinamobileai.domain.Course;
import com.itheim.chinamobileai.service.PackageService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyTool {
    @Autowired
    private PackageService PackageService;
    //根据条件筛选和查询套餐
    @Tool(description = "根据条件筛选和查询套餐")
    public List<Course> queryCourse(@ToolParam(description = "查询条件") CourseQuery query){
        //sql:select * from package where edu < ? and traffic = ? and call = ? group by
      QueryWrapper<Course> qw = new QueryWrapper<>();
      qw.le(query.getEdu() != null, "edu", query.getEdu());
      qw.eq(query.getTraffic() != null, "traffic", query.getTraffic());
      qw.eq(query.getCall() != null, "call", query.getCall());
        List<CourseQuery.Srot> srot = query.getSrot();
        if (CollUtil.isNotEmpty(srot)){
            for (CourseQuery.Srot s : srot) {
                qw.orderBy(s.getField() != null, s.getIsAsc(), s.getField());
            }
        }
        return PackageService.list(qw);
    }

}
